package com.ithema.config;

import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration//就可以被springboot自动给扫描上了
public class MpConfig {
//    ms提供了  分页功能拦截器  只有配置才能进行分页功能
    @Bean//该组件名叫mpInterceptor   返回值为MybatisPlusInterceptor
    public MybatisPlusInterceptor mpInterceptor() {
        //1. 定义MP拦截器
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        //2. 添加分页内部拦截器  PaginationInnerInterceptor
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor());
        //3. 添加 乐观锁的拦截器  2000人一下    OptimisticLockerInnerInterceptor
        interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
        return interceptor;
    }
}
